<?php use_stylesheets_for_form($form) ?>
<?php use_javascripts_for_form($form) ?>
<?php if($form->getObject()->isNew()){
	throw new Exception("this form only acept edit mode");
}
$whitPrices=false;
?>
<div>
<?php if($form->hasErrors()){
	echo __("Los Precios no se han guardado correctamente debido a que hay un error en la información que usted esta suministrado, por favor revise los formularios y asegurese de que la información es correcta ");
}?>
<div>
	<?php echo $form->renderGlobalErrors();?>
	<?php echo $form["price"]->renderError();?>
</div>
<form action="<?php echo url_for('publication_prices/updatePricesByPublication?id='.$form->getObject()->getId()) ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
<?php echo $form->renderHiddenFields(true);

?>
<?php echo $form["price"] ?>
<a href="#" class="new_price button" style="float: right"><?php echo __("Nuevo Precio")?></a>
<br /><br />
<div id="main_form">
	<?php
	$mainFormPrices="prices"; 
	foreach ($form->getEmbeddedForm($mainFormPrices)->getEmbeddedForms() as $key=>$objFormPrice){
		$whitPrices=true;
		$fieldFormPrice=$form[$mainFormPrices][$key];
		?>
		<h3>
			<?php echo $objFormPrice->getObject()->getDescription();?>
			<span class="adm-total-price"> <?php echo $objFormPrice->getObject()->getTotalPrice()?> BsF</span>
			<span class="error"><?php if($objFormPrice->hasErrors()){ echo __("Error");}?></span>
		</h3>
		<div>
			<div>
				<div style="float:left; margin-right: 20px">
				<fieldset class="sh-b">
				<legend><?php echo __("Información general del Precio")?></legend>
					<table class="tbl-admin-form tbl-admin-form100" style="width:300px">
							<tbody>
									<?php echo $fieldFormPrice["price_type_id"]->renderRow()?>
									<?php echo $fieldFormPrice["description"]->renderRow()?>
									<tr>
										<th><?php echo __("Número de Coutas") ?></th>
										<td><?php echo $objFormPrice->getObject()->getNumPrices(), $fieldFormPrice["num_prices"]->render()?></td>
									</tr>
									<tr>
										<th><?php echo __("Porcentajes")?></th>
										<td>
											<table style="width:100%">
												<tbody>
													<tr>
														<th><?php echo $fieldFormPrice["percentage_type"]->renderLabel()," ",$fieldFormPrice["percentage_type"]->renderError() ?></th>
														<th><?php echo $fieldFormPrice["percentage"]->renderLabel()," ",$fieldFormPrice["percentage"]->renderError() ?></th>
													</tr>
													<tr>
														<td style="width:70%"><?php echo $fieldFormPrice["percentage_type"]->render(array("style"=>"width:100%"))?></td>
														<td style="width:30%"><?php echo $fieldFormPrice["percentage"]->render(array("style"=>"width:100%"))?></td>
													</tr>
												</tbody>
											</table>
											</td>
								   </tr>
								   <?php if (!$objFormPrice->getObject()->isNew()): ?>
								   <tr>
								   	<td colspan="2">
						            <?php echo link_to('Eliminar Este Precio', 'publication_prices/delete?id='.$objFormPrice->getObject()->getId(), array('method' => 'delete', 'confirm' => '¿Used esta seguro de eliminar este precio?')) ?>
						            </td>
						            </tr>
						          <?php endif; ?>
							</tbody>
					</table>
				</fieldset>
				</div>
				<div >
					<fieldset class="sh-b">
				<legend><?php echo __("Detalle de los pagos")?></legend>
					<?php foreach($objFormPrice->getEmbeddedForm("custom")->getEmbeddedForms() as $key=>$val){
						$fieldCustom=$fieldFormPrice["custom"][$key];

						?>
					<div class="sh-b1">
						<table class="tbl-admin-form tbl-admin-form">
							<?php echo $fieldCustom["description"]->renderRow();?>
							<?php echo $fieldCustom["amount"]->renderRow(); ?>
							<?php echo $fieldCustom["expires_at"]->renderRow(array("class"=>"input-date")); ?>
						</table>
					</div>
					<?php } ?>
					</fieldset>
				</div>
				
			</div>
		</div>
		<?php 
		
	}?>
</div>
<br />
  <div >
  		  &nbsp;<a class="button" href="<?php echo url_for('publication/index') ?>"><?php echo __("Listado")?></a>
          &nbsp;<a href="#" class="new_price button" ><?php echo __("Nuevo Precio")?></a>
          &nbsp;<input class="button" type="submit" value="<?php echo __("Guardar")?>" />
  </div>
</form>
</div>
<div id="form_new_price" style="width: 400px">
	<form  action="<?php echo url_for("publication_prices/create?id={$form->getObject()->getId()}")?>" method="post">
	<p><strong>Warning:</strong> Procure haber guardado toda la información del formulario principal antes de agregar un nuevo precio, la información que no haya sido guardada se perderá. </p>
		<table style="width: 100%" class="tbl-admin-form tbl-admin-form100">
		<?php echo $form_new?>
		</table>
	</form>
</div>
<script type="text/javascript">
<?php $shoNewForm=$form_new->hasErrors()?true:!$whitPrices;?>
(function($){
	$("ul.radio_list").buttonset();
	$("#form_new_price").dialog({modal:true,
								 autoOpen:<?php echo var_export($shoNewForm,true)?>,
								 width: "500px",
								 
								 buttons:{
									 		"Guardar": function(ui){ $(this).find("form").submit(); },
											"Cancelar": function(){$(this).dialog("close");}
 										 }
								}
								);

	$("#main_form").accordion({
		autoHeight: false,
		navigation: true,
		collapsible: true});

	$(".new_price").click(function(){
		$("#form_new_price").dialog("open");
	});
	
}

)(jQuery);

</script>
<?php //echo $form->getObject()->getPublicationPrices()->get(0)->buildNewCustomization()?>